package Text7;

import java.util.*;

public class Main {
    static final int N = 10;
    static int x, res;
    static boolean st[] = new boolean[N];
    static boolean backup[] = new boolean[N];

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        x = scanner.nextInt();
        dfs_a(0);
        System.out.println(res);
    }

    private static void dfs_a(int a) {
        if (a >= x) {
            return;
        }
        if (a > 0) {
            dfs_c(a, 0);
        }
        for (int i = 1; i <= 9; i++) {
            if (!st[i]) {
                st[i] = true;
                dfs_a(a * 10 + i);
                st[i] = false;
            }
        }
    }

    private static void dfs_c(int a, int c) {
        if (c > 0) {
            if (check(a, c)) {
                res++;
            }
        }
        for (int i = 1; i <= 9; i++) {
            if (!st[i]) {
                st[i] = true;
                dfs_c(a, c * 10 + i);
                st[i] = false;
            }
        }
    }

    private static boolean check(int a, int c) {
        long b = x * (long)c - a * c;
        backup = st.clone();
        if(b==0){
            return false;
        }
        while (b > 0) {
            int t = (int)(b % 10);
            b/=10;
            if(t==0||backup[t]){
                return false;
            }
            backup[t] = true;
        }
        for (int i = 1; i <= 9; i++) {
            if (!backup[i]) {
                return false;
            }
        }
        return true;
    }
}
